package mains;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;

import app.Customer;
import app.Payment;

public class Main5AllPaymentsToMerchant {

    private static final String PERSISTENCE_UNIT_NAME = "CashM";
    private static EntityManagerFactory factory;

    public static void main(String[] args) {
	factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
	EntityManager em = factory.createEntityManager();
	Customer customer = null;

	TypedQuery<Payment> query = em.createQuery("SELECT p FROM Payment p Where p.merchant.id = 1",
		Payment.class);
	List<Payment> listP = null;

	try {
	    listP = query.getResultList();
	} finally {
	    em.close();
	}
	if (listP != null) {
	    for (Payment p : listP) {
		System.out.println(p.toString());
	    }
	}

    }

}
